package leetcode_day._2021._202109._0110;

import general_class.ListNode;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/9/2 9:02
 * 链表中倒数第k个节点
 * 算法：快慢指针
 */
public class _02_剑指offer22 {

    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode tmp = head;
        for (int i = 0; i < k; i++) tmp = tmp.next;
        while (tmp != null) {
            tmp = tmp.next;
            head = head.next;
        }
        return head;
    }

}
